package com.lagou.mr;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class IntegerSortDriver {

    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        Configuration conf = new Configuration();
        //获取job对象
        Job job = Job.getInstance(conf);
        //设置启动类
        job.setJarByClass(IntegerSortDriver.class);
        //设置mapper
        job.setMapperClass(IntegerSortMapper.class);
        //设置reducer
        job.setReducerClass(IntegerSortReducer.class);
        //设置map输出
        job.setOutputKeyClass(IntWritable.class);
        job.setMapOutputValueClass(NullWritable.class);
        //设置最终输出
        job.setOutputKeyClass(IntWritable.class);
        job.setOutputValueClass(IntWritable.class);
        //指定输入数据路径
        FileInputFormat.setInputPaths(job, new Path(args[0]));//从参数获取输入路径和输出路径
        //指定处理结果路径
        FileOutputFormat.setOutputPath(job, new Path(args[1]));
        //提交任务
        boolean b = job.waitForCompletion(true);
        int code = b?0:-1;
        System.exit(code);
    }
}
